package com.dmz.book.login.controller;
import com.dmz.book.common.Itools.Helper;
import com.dmz.book.common.md5.MD5Code;
import com.dmz.book.entitys.AdminsEntity;
import com.dmz.book.entitys.JsonResultEntity;
import com.dmz.book.entitys.AdminsEntity;
import com.dmz.book.login.server.AdminLoginService;
import com.dmz.book.login.server.Impl.AdminLoginServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private AdminLoginService adService;
    @ResponseBody
    @RequestMapping("/submit")
    public JsonResultEntity<AdminsEntity> loginin(HttpServletRequest request){
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        String passwordmd5=new MD5Code().getMD5ofStr("dmz081027");
        String access_token= Helper.getRandomString(12);
        AdminsEntity adminsEntity=new AdminsEntity(username,passwordmd5);
        adminsEntity=adService.Loginin(adminsEntity);
        HashMap<String,Object> map = new HashMap<>();
        System.out.println(adminsEntity);
        map.put("access_token",access_token);
        map.put("userinfo",adminsEntity);
        return new JsonResultEntity(map);
    }

    @RequestMapping("/index")
    public String login(){

        return "index";
    }

    @ResponseBody
    @RequestMapping("/layout")
    public JsonResultEntity layout(){

        return new JsonResultEntity("0","退出成功");
    }


}
